package com.tourism.admin.handles;

import com.tourism.admin.exceptions.GlobalException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author linli
 * at 18-3-31 下午3:32
 * 异常处理
 */

@ControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Object handle(Exception e){
        if(e instanceof GlobalException){
            GlobalException globalException = (GlobalException) e;
            //控制台查看异常信息
            return globalException.getMessage();
        }else if(e instanceof org.mybatis.spring.MyBatisSystemException){
            return "请检查网络设置";
        }
        else {
            return "未知错误";
        }
    }
}
